from app.p_main_application import MainApplication
from app.s_happy_record import HappyRecordServer
from app.s_sport_record import SportRecordServer

import threading
import queue

from component.c_log import LOG

TAG = "app_main_application"
class HappyRecordApp:
    def __init__(self):
        self.app_data_queue = queue.Queue()
        self.happy_submit_event = threading.Event()
        self.sport_submit_event = threading.Event()

    def run(self):
        # 启动Happy服务器线程
        LOG(TAG, "启动Happy服务器线程")
        happy_record_server = HappyRecordServer(self.app_data_queue, self.happy_submit_event)
        happy_record_server_thread = threading.Thread(target=happy_record_server.run)
        happy_record_server_thread.daemon = True
        happy_record_server_thread.start()

        # 启动Sport服务器线程
        LOG(TAG, "启动Sport服务器线程")
        sport_record_server = SportRecordServer(self.app_data_queue, self.sport_submit_event)
        sport_record_server_thread = threading.Thread(target=sport_record_server.run)
        sport_record_server_thread.daemon = True
        sport_record_server_thread.start()

        # 在主线程启动页面
        LOG(TAG, "启动页面")
        happy_record_page = MainApplication(self.app_data_queue, self.happy_submit_event,self.sport_submit_event)
        happy_record_page.run()  

if __name__ == '__main__':
    app = MainApplication()
    app.run()